package com.nondo.rdp.finance.endpoint.wap.app;

import com.nondo.rdp.finance.domain.Activity;
import com.nondo.rdp.finance.domain.Setting;
import com.nondo.rdp.finance.service.ActivityService;
import com.nondo.rdp.finance.service.SettingService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.env.Environment;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.HashMap;
import java.util.Map;

@Controller("apiWapDownload")
@RequestMapping("/wap/app/download")
public class DownloadEndpoint {

    @Autowired
    ActivityService activityService;

    @Autowired
    private Environment environment;

    @Autowired
    private SettingService settingService;

    /**
     * 下载
     *
     * @param request
     * @param response
     * @return
     */
    @RequestMapping("")
    public ModelAndView getDownload(HttpServletRequest request, HttpServletResponse response) {
        ModelAndView mv = new ModelAndView("wap/app/download/index");

        Map map = new HashMap();

        Setting downloadIos = this.settingService.findByName("DOWNLOAD_IOS");
        Setting downloadAndroid = this.settingService.findByName("DOWNLOAD_ANDROID");

        if (downloadIos == null || downloadAndroid == null) {
            mv.addObject("downloadIos", "https://www.luobobb.com");
            mv.addObject("downloadAndroid", "https://www.luobobb.com");
        } else {
            mv.addObject("downloadIos", downloadIos.getValue());
            mv.addObject("downloadAndroid", downloadAndroid.getValue());
        }

        //基础地址
        mv.addObject("baseUrl", environment.getProperty("app.base_url"));

        return mv;
    }
}